<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="css/eui.css">
</head>
<body>

<div id="app">
    <center>
        <el-page-header style="background-color:#0095d7;color: white;line-height: 60px;"
                        @back="goBack()" content="发布轮播图页面"></el-page-header>
        <el-divider></el-divider>
        <el-card style="width: 200px;">
            <el-upload
                    action="/upload"
                    name="picFile"
                    :limit="5"
                    list-type="picture-card"
                    :on-preview="handlePictureCardPreview"
                    :on-success="handleSuccess"
                    :on-remove="handleRemove">
                <i class="el-icon-plus"></i>
            </el-upload>
            <el-dialog :visible.sync="dialogVisible">
                <img width="100%" :src="dialogImageUrl" alt="">
            </el-dialog>
            <el-button @click="insert()">发布</el-button>
        </el-card>
    </center>



</div>
</body>
<!-- import Vue before Element -->
<script src="js/vue.js"></script>
<!-- import JavaScript -->
<script src="js/eui.js"></script>
<script src="js/axios.min.js"></script>

<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                dialogImageUrl: '',
                dialogVisible: false,
               banner:{
                    url:""
                }
            }
        },
        methods: {
            handleRemove(file, fileList) {
                console.log(file, fileList);
                console.log(file.response)
                axios.get("/remove?name="+file.response).then(function (response) {
                    console.log("服务器图片已删除")
                })
            },

            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.url;
                this.dialogVisible = true;
            },
            handleSuccess(response,file,fileList){
                console.log("文件上床成功,图片名="+response);
                v.banner.url=response;

            },
            insert(){
                if (v.banner.url==""){
                    alert("上床内容不能为空!")
                    return;
                }
                    alert("添加完成!")
                    location.href="/"

            },
            goBack(){
                history.back();
            }

        }
    })
</script>
</html>